package com.shangxia.monomer.study.designPatterns.creationType.factory;

import com.shangxia.monomer.study.designPatterns.creationType.factory.base.*;
import com.shangxia.monomer.study.designPatterns.creationType.factory.ordinary.FruitFactory;
import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: monomer
 * @ClassName: Application
 * @Time: 2021/7/18
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class Application {
    public static void main(String[] args) {
        FruitFactory fruitFactory = new FruitFactory();
        Fruit fruit1 = fruitFactory.createFruit(FruitNameEnum.BANANA);
        fruit1.say();
        System.out.println(fruit1.shape());
        Fruit fruit = createFruit(FruitNameEnum.APPLE);
        fruit.say();
        System.out.println(fruit.shape());
    }

    private static Fruit createFruit(FruitNameEnum name) {
        return SimpleFactory.createFruit(name);
    }
}

/**
 * 简单工厂 编码风格
 */
class SimpleFactory {
    public static Fruit createFruit(FruitNameEnum name) {
        switch (name) {
            case APPLE:
                return new Apple("apple", ColourEnum.ERD);
            case BANANA:
                return new Banana("banana", ColourEnum.YELLOW);
            case ORANGE:
                return new Orange("", ColourEnum.ORANGE);
            default:
                return null;
        }
    }
}
